<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :footer="null"
    cancelText="关闭">

    <table id="table_report" class="table table-striped table-bordered table-hover">
      <tr>
        <td style="width:90px;text-align: right;padding-top: 80px;">基本信息:</td>
        <td>
          <p style="float: left;">
             更新时间：<span id="updateTime" >
           {{result.updateTime }}
                      </span><br>
             姓名：<span id="userName" >
           {{result.userName }}
                    </span><br>
             手机号：<span id="mobile" >
           {{result.mobile }}
                    </span><br>
             证件类型：<span id="certType" >
           {{result.certType }}
                    </span><br>
             性别：<span id="gender" >
            <span v-if='result.gender==1'>男</span>
            <span v-if='result.gender==2'>女</span>
                    </span><br>
             备注：<span id="remark" >
           {{result.remark }}
                    </span><br>
             国籍：<span id="nation" >
           {{result.nation }}
                    </span><br>
             民族：<span id="ethnic" >
           {{result.ethnic }}
                    </span><br>
             籍贯：<span id="hometown" >
           {{result.hometown }}
                    </span><br>
             出生日期：<span id="birthday" >
           {{result.birthday }}
                    </span><br>
             住址：<span id="address" >
           {{result.address }}
                    </span><br>
             创建人：<span id="createUser" >
           {{result.createUser }}
                    </span><br>
             证件号：<span id="idCard" >
           {{result.idCard }}
                    </span><br>
            创建时间：<span id="createTime" >
           {{result.createTime }}
                    </span><br>
            人员类型：<span id='projectUserTypeName'>
            {{result.projectUserTypeName}}
          </span><br>
            人员类型：<span id='departmentName'>
            {{result.departmentName}}
          </span><br>
            所在位置：<span id='locateName'>
            {{result.locateName}}
          </span>
	          </p>
			  </td>
      </tr>
      <tr>
        <td style="text-align: center;" colspan="10">
          <a-button type="primary" @click="close">关闭</a-button>
        </td>
      </tr>
    </table>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  export default {
    name: "UserModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
         result: {},
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        userName:{rules: [{ required: true, message: '请输入姓名!' }]},
        },
      }
    },
    created () {
    },
    methods: {
      edit (record) {
       Object.assign(this.result, record)
       this.visible = true
      },
      close () {
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.updateTime = formData.updateTime?formData.updateTime.format('YYYY-MM-DD HH:mm:ss'):null;

            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style lang="less" scoped>

</style>